package com.hns.tool.export.pdf;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;

/**
 * 导出PDF专用设置实体
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
public class ExportPdfEntity {
    //------------全局配置start----------------
	//文档标题
    private String title;
    //字体
    private Font font;
    //默认字体
    private static BaseFont baseFont;
    static {
        // 默认字体
        try {
            baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //内容类别 （目前只支持图片和表单） : 图片格式  :IMAGE,表单数据:DATALIST
    private String contentType; 
    //页长
    private String pageSize = "100";
    //显示给用户文件名
    private String showName;
    //分页事件
    private PdfPageEventHelper pageEvent;
    //------------全局配置end------------------
    //------------图片格式start----------------
    //图片路径
    private String imgPath;
    
    //------------图片格式end------------------
    
    //------------表单数据start----------------
    //表头字段
    private List tableHeaderName;
    //表头各单元格宽度 
    private int[] headerwidths;
    //自定义表格数据 
    private PdfPTable custom;
    //自定义表头
    private PdfPTable tableHeader;
    //表格与实体对应字段名对象 
    private List<CellField> tableField;
    //表格内容 
    private List tableContent;
    //------------表单数据end------------------
    
    public ExportPdfEntity(){
    }
    
    public ExportPdfEntity(List<String> headList, List<String> fieldList, List dataSource, String showName){
        this.tableHeaderName = headList;
        List<CellField> tableField = new ArrayList<CellField>();
        for(int i=0;i<fieldList.size(); i++){
            CellField cell = new CellField();
            cell.setFieldName(fieldList.get(i));
            tableField.add(cell);
        }
        this.tableField = tableField;
        this.tableContent = dataSource;
        this.showName = showName;
        this.title = title;
    }
    
	public int getNumColumns() {
		return tableField.size();
	}

	public PdfPageEventHelper getPageEvent() {
		return pageEvent;
	}

	public void setPageEvent(PdfPageEventHelper pageEvent) {
		this.pageEvent = pageEvent;
	}

	public List getTableContent() {
		return tableContent;
	}

	public void setTableContent(List tableContent) {
		this.tableContent = tableContent;
	}

    public String getShowName() {
		try {
			return showName != null ? new String(showName.getBytes("gbk"), "ISO8859-1") : showName;
		} catch (UnsupportedEncodingException e) {
		}
		return null;
	}

	public void setShowName(String showName) {
		this.showName = showName;
	}

	public PdfPTable getTableHeader() {
		return tableHeader;
	}

	public void setTableHeader(PdfPTable tableHeader) {
		this.tableHeader = tableHeader;
	}

	public int[] getHeaderwidths() {
		return headerwidths;
	}

	public void setHeaderwidths(int[] headerwidths) {
		this.headerwidths = headerwidths;
	}

	public List getTableHeaderName() {
		return tableHeaderName;
	}

	public void setTableHeaderName(List tableHeaderName) {
		this.tableHeaderName = tableHeaderName;
	}

	public String getTitle() {
		return title != null ? title.trim() : title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Font getFont() {
		return font == null ? new Font(baseFont, 12, Font.BOLD) : font;
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public BaseFont getBaseFont() {
		return baseFont;
	}

	public ExportPdfEntity setBaseFont(BaseFont baseFont) {
		ExportPdfEntity.baseFont = baseFont;
		return this;
	}

	public PdfPTable getCustom() {
		return custom;
	}

	public void setCustom(PdfPTable custom) {
		this.custom = custom;
	}

	public List<CellField> getTableField() {
		return tableField;
	}

	public void setTableField(List<CellField> tableField) {
		this.tableField = tableField;
	}

	public String getPageSize() {
		return pageSize != null ? pageSize.trim() : pageSize;
	}

	public void setPageSize(String pageSize) {
		this.pageSize = pageSize;
	}

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }

}
